Bureau of Labor Statistics Time Series Updates
Purpose
Extract and review publicly available time series files for selected economic indicators, published by the Bureau of Labor Statistics (BLS), perform light cleaning, and save copies of the cleaned files for use in forecasting models and other projects.
Data Sources
Selected data represent measures of inflation and unemployment series:
Consumer Price Index (CU) series - SEME Health insurance - SEMF01 Prescription Drugs - SAM1 Medical care commodities
Unemployment Rate series - LAUST Unadjusted unemployment rates
#remotes::install_github("juba/rmdformats")
.libPaths(c(.libPaths(), "~/R/x86_64-redhat-linux-gnu-library/3.6"))
suppressMessages(library(dplyr))
suppressMessages(library(zoo))
suppressMessages(library(glue))
suppressMessages(library(ggplot2))
# cu.data.15.USMedical series: All US Medical (area_code 0000, item_code SAM, SEM, SS57)
CU.dta <- read.table("https://download.bls.gov/pub/time.series/cu/cu.data.15.USMedical", header = TRUE,fill=TRUE)
# 2021-03-15: Add the Chained CPI-All Urban Consumers.
# SUUR0000SA0: All items in U.S. city average, all urban consumers, chained, not seasonally adjusted
CPI.dta <-read.table("https://download.bls.gov/pub/time.series/su/su.data.1.AllItems", header = TRUE,fill=TRUE)
# Unemployment
LA.dta <- read.table("https://download.bls.gov/pub/time.series/la/la.data.11.California", header = TRUE,fill=TRUE)
CPI <- subset(CPI.dta,series_id =="SUUR0000SA0")
CU_ins <- subset(CU.dta,series_id =="CUUR0000SEME")
CU_scrips <- subset(CU.dta,series_id =="CUUR0000SEMF01")
CU_med <- subset(CU.dta,series_id =="CUSR0000SAM1")
# Rates only
LA_rates_ca <- subset(LA.dta,value <100 & series_id =="LAUST060000000000003") Data Cleaning
Add dates, perform light cleanup, and save copies. Updates will overwrite any files created previously.
dfs <- list(ins=CU_ins, scrips=CU_scrips,
med = CU_med, rates_ca =LA_rates_ca,
cpi = CPI)
dfnms <- names(dfs)
# Helper function
fn_dtorg <- function(df) {
df <- df %>%
mutate(dt = as.yearmon(paste(year, substr(period,2,4), sep = "-")),
dt2 = as.Date(dt))
df <- df[order(df$dt),]
df <- subset(df, !is.na(dt))
return(df)
}
fn_forg <- function(framelst) {
lapply(framelst, FUN=fn_dtorg)
}
dfscln <- fn_forg(dfs)
invisible(list2env(dfscln,envir=.GlobalEnv)) # split and replace Consumer Price Index (CPI) time series data
These estimates reflect consumer purchasing for all urban consumers (CU), published by the U.S. Bureau of Labor Statistics (BLS). The CPI measures change, over time, of the prices of goods and services by comparing the typical cost of a sample “market basket” of goods at a given time, relative to an earlier baseline or reference period. Updates are usually available monthly.
Chained CPI
tmp <- cpi
dtmin <- min(tmp$dt2)
dtmax <- max(tmp$dt2)
ymin <- min(tmp$value)
suppressMessages(library(plotly))
g<- ggplot(data=tmp, aes(x=dt2,y=value)) +
geom_line(color="dodgerblue3") +
scale_x_date(date_labels = "%Y", date_breaks ="5 years") +
ylab("Chained CPI") +
xlab("") +
theme_minimal()
ggp_build <- plotly_build(g)
ggp_build$layout$height = 1500
ggp_build$layout$width = 600
ggp_build %>% layout(title = list(text = glue('<br>','U.S. Chained Consumer Price Index (CPI)',
'<br>',
'<sup>',
'{dtmin} through {dtmax}',
'</sup>')))CPI: Medical Care Services - Prescription Drugs (SEMF01)
This index includes total reimbursements to retailers for:
- Drugs purchased with a prescription at a retail, mail order, or internet pharmacy.
- All eligible payers for a single prescription, including self-pay, commercial insurance, and Medicare Part D.
This index excludes:
- Special discounts provided to pharmacies by manufacturers
- Manufacturer rebate for 340B pharmacies
- Prescription drugs consumed and paid for during hospital visits
tmp <- subset(scrips,dt2 >= as.Date("1985-01-01"))
dtmin <- min(tmp$dt2)
dtmax <- max(tmp$dt2)
ymin <- min(tmp$value)
suppressMessages(library(plotly))
g<- ggplot(data=tmp, aes(x=dt2,y=value)) +
geom_line(color="dodgerblue3") +
scale_x_date(date_labels = "%Y", date_breaks ="5 years") +
ylab("CPI - Prescription Drugs") +
xlab("") +
theme_minimal()
ggp_build <- plotly_build(g)
ggp_build$layout$height = 1500
ggp_build$layout$width = 600
ggp_build %>% layout(title = list(text = glue('<br>','U.S. Consumer Price Index (CPI) - Prescription Drugs',
'<br>',
'<sup>',
'{dtmin} through {dtmax}',
'</sup>')))CPI: Medical Care Services - Health Insurance (SEME)
This index includes all out of pocket expenses for:
- Health insurance premiums paid for by the consumer, including Medicare Part B; and
- Health insurance premiums deducted from employee paychecks.
This index excludes:
- Employer paid portions of insurance premiums
- Tax-funded medical care (e.g., Medicare Part A and Medicaid).
This index does not control for differences or changes in policy benefits and is measured using the retained earnings method, which looks at insurance company earnings (premium payments vs. benefits paid out on behalf of customers).
Insurance data: ins.csv
dtmin <- min(ins$dt2)
dtmax <- max(ins$dt2)
ymin <- min(ins$value)
g <- ggplot(data=ins, aes(x=dt2,y=value)) +
geom_line(color="forestgreen") +
scale_x_date(date_labels = "%Y", date_breaks ="1 years") +
ylab("CPI - Health Insurance") +
xlab("") +
theme_minimal()
ggp_build <- plotly_build(g)
ggp_build$layout$height = 1500
ggp_build$layout$width = 600
ggp_build %>% layout(title = list(text = glue('<br>','U.S. Consumer Price Index (CPI) - Health Insurance',
'<br>',
'<sup>',
'{dtmin} through {dtmax}',
'</sup>')))CPI: Medical Care Services - Medical care commodities (SAM1)
This index includes all out of pocket expenses for:
- All prescription and over-the-counter drugs
- Nonprescription medicines and dressings used externally, contraceptives, and supportive and convalescent medical equipment (e.g., adhesive strips, heating pads, athletic supporters, and wheelchairs).
This index excludes:
- Physicians, dentists, eye care providers, and other medical professionals
- Services provided to inpatients and outpatients. Includes emergency room visits, nursing home care and adult day care.
- Health insurance
Medical care commodities data: meds.csv
tmp <- subset(med,dt2 >= as.Date("1985-01-01"))
dtmin <- min(tmp$dt2)
dtmax <- max(tmp$dt2)
ymin <- min(tmp$value)
g <- ggplot(data=tmp, aes(x=dt2,y=value)) +
geom_line(color="darkcyan") +
scale_x_date(date_labels = "%Y", date_breaks ="5 years") +
ylab("CPI - Medical Commodities") +
xlab("") +
theme_minimal()
ggp_build <- plotly_build(g)
ggp_build$layout$height = 1500
ggp_build$layout$width = 600
ggp_build %>% layout(title = list(text = glue('<br>','U.S. Consumer Price Index (CPI) - Medical Commodities',
'<br>',
'<sup>',
'{dtmin} through {dtmax}',
'</sup>')))Local Area Unemployment Statistics (LAUST-06)
This measure reflects unemployment in the civilian labor force. State estimates are calculated from signal plus noise models combining current and historical data from the Current Population Survey (CPS), state unemployment insurance systems, the Current Employment Statistics survey, and American Community Survey (ACS).
Estimates are updated each month, with revised estimates for the prior month. The current month’s rate is provisional until subsequent data are received. Estimates are annually updated for the previous five years each April.
tmp <- subset(rates_ca,dt2 >= as.Date("1985-01-01"))
dtmin <- min(tmp$dt2)
dtmax <- max(tmp$dt2)
ymin <- min(tmp$value)
g<- ggplot(data=tmp, aes(x=dt2,y=value)) +
geom_line(color="tomato") +
scale_x_date(date_labels = "%Y", date_breaks ="5 years") +
ylab("Unemployment rate") +
xlab("") +
theme_minimal()
ggp_build <- plotly_build(g)
ggp_build$layout$height = 1500
ggp_build$layout$width = 600
ggp_build %>% layout(title = list(text = glue('<br>','Local Area Unemployment rate, California',
'<br>',
'<sup>',
'{dtmin} through {dtmax}',
'</sup>')))write.csv(ins, "ins.csv", row.names=FALSE)
write.csv(med,"meds.csv",row.names=FALSE)
write.csv(cpi,"cpi.csv",row.names=FALSE)Resources
Bureau of Labor Statistics, “Measuring Price Change in the CPI: Medical care” https://www.bls.gov/cpi/factsheets/medical-care.htm
BLS Handbook of Methods, Local Area Unemployment Statistics. https://www.bls.gov/opub/hom/lau/home.htm
Bureau of Labor Statistics, Time series file layouts and item definitions for medical care and local area unemployment series: https://download.bls.gov/pub/time.series/cu/cu.item and https://www.bls.gov/lau/lauov.htm title: “BLS Updates”
Julien Barnier (2022). rmdformats: HTML Output Formats and Templates for ‘rmarkdown’ Documents. R package version 1.0.4.9000. https://github.com/juba/rmdformats